<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<%String path = request.getContextPath(); %>
<title>组织机构展示列表</title>
<script type="text/javascript" src="<%=path%>/js/jquery.js"></script>
 <script type="text/javascript" src="<%=path %>/js/Common.js"></script>
  <link rel="stylesheet" type="text/css" href="<%=path %>/css/web.css" />
  <link rel="stylesheet" href="<%=path %>/css/Common.css" />
  <script type="text/javascript">
        $(function () {
            var leftOffset = ($(window).width() - $(".pop-form").width()) / 2;
            var topOffset = ($(window).height() - $(".pop-form").height()) / 2 - 50;
            $(".pop-form").css("left", leftOffset);
            $(".pop-form").css("top", topOffset);
            $(".pop-close").click(function () {
                closeForm();
            });
            
            //展示相应的数据
            initOrgData();
            
            
        });
        
        //加载车辆数据
       function  initOrgData(){
    	    var data = {"id":1,
    	    		    "platform":"web",
    	    		     "uid":"d4bdb016a3b94a3cb319e6d32ccdf4c3",
    	    		     "parameter":{}};	
    	     
    	    $.ajax({
                url: "<%=path%>/organization/queryOrganizationInfo.htm",
                data: JSON.stringify(data),
                type : "POST",
                contentType:"application/json",
                dataType: "json",
                success: function (result) {
                	showOrgData(result);
                }
            });
    	    
            }
        
         /*展示组织信息*/
        function showOrgData(result){
        	 var cars = $.parseJSON(result);
        	 if(cars.status=="100000"){
        		var data = cars.result;
                $.each(data, function(index, val) {
                 // var id = val.id;
                 var statusName = "";
                  if (val.status=="0") {
                    statusName = "未启用";
                  }else if (val.status=="1") {
                     statusName = "启用";
                  }
                 var carhtml = "<tr><td>"+val.or_name
                            +"</td><td>"+val.strengths+"</td><td>"
                            +val.longitude+"</td><td>"
                            +val.latitude+"</td><td>"
                            +val.address+"</td><td>"
                            +val.remark+"</td><td style='width:50px;'>"
                            +"<span><a class='con-tb-img-edit' title='编辑' href='javascript:;' onclick="+"editRecord('"+val.or_id+"');"+"></a></span></td>"
                            +"<td style='width:50px;'>"
                            +"<span><a class='con-tb-img-delete' title='删除' href='javascript:;' "
                            +"onclick="+"DeleteRecord('"+val.or_id+"');"+"></a></span></td></tr>";
                    $("#car_table").append(carhtml);
                    
                });

        	 }else{
        		 alert();
        	 }
        }
        function editsaves(){
        var $msg  =  $(".pop-message span");
         if ($.trim($("#or_name").val())=="") {
                  $msg.text("医院名不能为空");
                  $msg.val("").focus();
                   return;
             }
        
        $.ajax({
			async : false,
			type : "POST",
			url : "<%=path%>/organization/turntoaddOrganization.htm",
			data : $("form").serialize(),
			dataType: "json",
			success : function(result) {
				var resultData = $.parseJSON(result);
                if (resultData.status=="100000") {
                	if(resultData.result>=1){
                		$(".pop-message span").text("医院已经存在，请重新添加!");
                	}else{
                		$(".pop-message span").text("添加成功!");
                     	setTimeout(function () {
						    window.location.reload();
						 }, 700);
                	}
                }
			}
		});
        }

        //编辑保存
        function editsave(tmp) {
        	var carData = {"or_id":$("#edit_or_id").val(),"or_name": $("#edit_or_name").val(),"strengths":$("#edit_strengths").val(),"longitude":$("#edit_longitude").val(),"latitude":$("#edit_latitude").val(),"address":$("#edit_address").val(),"remark": $("#edit_remark").val()};   
			$.ajax({
				url : "<%=path%>/organization/editorganization.htm",
                data: carData,
                type : "POST",
                dataType: "json",
				success : function(result) {
					var resultData = $.parseJSON(result);
                    if (resultData.status=="100004") {
                       $(".pop-message span").text("医院已经存在，请重新添加!");
                    }else if(resultData.status=="100000"){
                     	$(".pop-message span").text("修改成功!");
                     	setTimeout(function () {
						    window.location.reload();
						 }, 700);
                    } 
				}
			});
        }

        //编辑
        function editRecord(id) {
            $("#editReset").removeAttr("onclick");
            displayForm('parameter-edit');
			$.ajax({
				async : false,
				type : "POST",
				url : "<%=path%>/organization/turntoOrganizationInfo.htm",
				data : {"or_id":id},
				dataType: "json",
				success : function(result) {
					var res = $.parseJSON(result);
               		if(res.status=="100000"){
               			var tmp = res.result[0];
               			$("#edit_or_name").val(tmp.or_name);
               			$("#edit_strengths").val(tmp.strengths);
               			$("#edit_longitude").val(tmp.longitude);
               			$("#edit_latitude").val(tmp.latitude);
               			$("#edit_address").val(tmp.address);
               			$("#edit_remark").val(tmp.remark);
               			$("#edit_or_id").val(tmp.or_id);
               		}
				}
			});
        }

        //显示弹出层
        function displayForm(formId) {
            if (formId != null) {
                $(".blacklayer").css("display", "block");
                $("#" + formId + "").fadeIn(100);
                $(".pop-table input:first").focus();
            }
        }

        //关闭弹出层
        function closeForm() {
            $(".blacklayer").hide();
            $(".pop-form").fadeOut(100);
            resetForm();
            resetMessage();
        }

        //重置表单
        function resetForm() {
            $(".pop-table input").val("");
            $("#reset").attr("onclick", "resetForm(); resetMessage();");
        }

        //编辑车辆信息重置表单
        function editResetForm(){
            $(".pop-table input[name!='editlicense_plate']").val("");
            $("#editReset").attr("onclick", "editResetForm(); resetMessage();");
        }

        //重置消息
        function resetMessage() {
            $(".pop-message span").text("");
        }
    </script>
</head>
<body>

    <div class="con-all">
        
        <div class="con-header">
            
            <div class="con-header-left">
                <div style="background-color: #E74C5E;width:15px; float:left; height:40px;"></div>
                <div style="text-align:left; color:black; font-size:11pt; ">
                    &nbsp;首页&nbsp;>&nbsp;基础管理&nbsp;>&nbsp;机构管理
                </div>
            </div>
            
            <div class="con-header-right">
                <a class="custom-btn" style="float:right;" onclick="displayForm('parameter-add');" href="javascript:;">添加</a>
            </div>
        </div>
        
        <div class="con-content">
            
            <table id="car_table" class="con-tb">
                <tr>
                    <th>医院名</th>
                    <th>专长</th>
                    <th>经度</th>
                    <th>纬度</th>
                    <th>地址</th>
                    <th>备注</th>
                    <th colspan="2">操作</th>
                </tr>
            </table>
        </div>
    </div>
    
<div class="blacklayer">
</div>
<div class="poplayer">
    <div class="tit">
        <span><!--标题文字--></span>
        <div class="close">X</div>
    </div>
    <div class="con">
        <div class="message">
            <!--内容区-->
        </div>
        <div class="dbutton">
            <a id="cancel" class="btn" href="javascript:;">取消</a>&nbsp;&nbsp;&nbsp;&nbsp;
            <a id="confirm" class="btn" href="javascript:;">确定</a>
        </div>
    </div>
</div>

    
    <div id="parameter-add" class="pop-form">
        <div class="pop-title">
            <span>医院信息</span>
            <div title="关闭" class="pop-close">X</div>
        </div>
        <div class="pop-content">
            
            <form id="form-parameter-edit">
                <input name="id" type="hidden" value="" />
                <table class="pop-table">
                    <tr>
                        <td style="text-align:right; padding-right:10px; width:100px;">名称</td>
                         <td>
                            <input name="or_name" id="or_name" class="text-input" type="text" maxlength="128" value="" placeholder="机构名" />
                            <span style="color:red;">*</span>
                        </td>
                       <td style="text-align: right; padding-right: 10px; width: 100px;">强项</td>
                        <td>
                            <input name="strengths" class="text-input" type="text" maxlength="128" value="" placeholder="强项" />
                        </td>
                    </tr>
                    <tr>
                    	 <td style="text-align: right; padding-right: 10px; width: 100px;">经度</td>
                        <td>
                            <input name="longitude" class="text-input" type="text" maxlength="128" value="" placeholder="经度" />
                        </td>
                        <td style="text-align: right; padding-right: 10px; width: 100px;">纬度</td>
                        <td>
                            <input name="latitude" class="text-input" type="text" maxlength="128" value="" placeholder="纬度" />
                        </td>
                    </tr>
                    <tr>
                    	<td style="text-align: right; padding-right: 10px; width: 100px;">地址</td>
                    	<td colspan="3">
                    		<input name="address" class="text-input" type="text" maxlength="128" value="" placeholder="地址" style="width:610px"/>
                    	</td>
                    </tr>
                    <tr>
                    	<td style="text-align: right; padding-right: 10px; width: 100px;">备注</td>
                    	<td colspan="3">
                    		<input name="remark" class="text-input" type="text" maxlength="128" value="" placeholder="备注" style="width:610px" />
                    	</td>
                    </tr>
                    <tr>
                        <td class="pop-message" colspan="4" style="text-align:center;color:red; height:30px; line-height:30px;"><span></span></td>
                    </tr>
                </table>
            </form>
            <div class="button-area">
                <div class="button-left">
                    <a id="reset" title="重置" class="custom-btn" onclick="resetForm(); resetMessage();" style="float: right; margin-right:10px; " href="javascript:;">重置</a>
                </div>
                <div class="button-right">
                    <a id="save" title="保存" class="custom-btn" onclick="editsaves();" style="float: left; margin-left:10px;" href="javascript:;">保存</a>
                </div>
            </div>
        </div>
    </div>


     <!-- 修改车辆信息 -->
    <div id="parameter-edit" class="pop-form">
         <div class="pop-title">
            <span>医院信息</span>
            <div title="关闭" class="pop-close">X</div>
        </div>
        <div class="pop-content">
            
            <form id="form-parameter-edit">
                <input name="id" type="hidden" value="" />
                <table class="pop-table">
                    <tr>
                        <td style="text-align:right; padding-right:10px; width:100px;">名称</td>
                         <td>
                            <input name="edit_or_name" id="edit_or_name" class="text-input" type="text" maxlength="128" value="" placeholder="机构名" />
                            <span style="color:red;">*</span>
                        </td>
                       <td style="text-align: right; padding-right: 10px; width: 100px;">强项</td>
                        <td>
                            <input name="edit_strengths" id="edit_strengths" class="text-input" type="text" maxlength="128" value="" placeholder="强项" />
                        </td>
                    </tr>
                    <tr>
                    	 <td style="text-align: right; padding-right: 10px; width: 100px;">经度</td>
                        <td>
                            <input name="edit_longitude" id="edit_longitude" class="text-input" type="text" maxlength="128" value="" placeholder="经度" />
                        </td>
                        <td style="text-align: right; padding-right: 10px; width: 100px;">纬度</td>
                        <td>
                            <input name="edit_latitude" id="edit_latitude" class="text-input" type="text" maxlength="128" value="" placeholder="纬度" />
                        </td>
                    </tr>
                    <tr>
                    	<td style="text-align: right; padding-right: 10px; width: 100px;">地址</td>
                    	<td colspan="3">
                    		<input name="edit_address" id="edit_address" class="text-input" type="text" maxlength="128" value="" placeholder="地址" style="width:610px"/>
                    	</td>
                    </tr>
                    <tr>
                    	<td style="text-align: right; padding-right: 10px; width: 100px;">备注</td>
                    	<td colspan="3">
                    		<input name="edit_remark" id="edit_remark" class="text-input" type="text" maxlength="128" value="" placeholder="备注" style="width:610px" />
                    	</td>
                    </tr>
                    <tr style="display:none">
                    	<td>
                    		
                    	</td>
                    	<td>
                    		<input name="edit_or_id" id="edit_or_id"/>
                    	</td>
                    </tr>
                    <tr>
                        <td class="pop-message" colspan="4" style="text-align:center;color:red; height:30px; line-height:30px;"><span></span></td>
                    </tr>
                </table>
            </form>
            <div class="button-area">
                <div class="button-left">
                    <a id="reset" title="重置" class="custom-btn" onclick="resetForm(); resetMessage();" style="float: right; margin-right:10px; " href="javascript:;">重置</a>
                </div>
                <div class="button-right">
                    <a id="save" title="保存" class="custom-btn" onclick="editsave();" style="float: left; margin-left:10px;" href="javascript:;">保存</a>
                </div>
            </div>
        </div>
    </div>


    <style>
        .td-table {
            width: 100%;
            margin: 0px 0px 10px 0px;
            padding: 0px;
            border-collapse: collapse;
            border: 0px;
        }

            .td-table tr {
                width: 100%;
                height: auto;
                margin: 0px;
                padding: 0px;
            }

                .td-table tr td {
                    width: auto;
                    height: 25px;
                    line-height: 25px;
                    border: 0px;
                    font-size: 12pt;
                }

        /*弹出表单层样式*/
        .pop-form {
            width: 750px;
            height: auto;
            position: fixed;
            box-sizing: border-box;
            border: solid 1px #E74C5E;
            background-color: white;
            z-index: 20000;
            display: none;
        }

        .pop-title {
            width: 748px;
            height: 35px;
            line-height: 35px;
            margin: 0px;
            padding: 0px;
            float: left;
            background-color: #E74C5E;
            color: white;
            box-sizing: border-box;
            padding-left: 10px;
        }

        .pop-close {
            text-align: center;
            float: right;
            width: 35px;
            height: 35px;
            /*background-color: #E74C5E;*/
        }

            .pop-close:hover {
                cursor: pointer;
                background-color: #eb6676;
            }

        .pop-content {
            width: 748px;
            height: auto;
            float: left;
            padding-bottom: 20px;
        }

        .pop-table {
            border: 0px;
            padding: 0px;
            margin-top: 20px;
            box-sizing: border-box;
            border: 0px;
            border-collapse: collapse;
            width: 100%;
        }

            .pop-table tr {
                width: 100%;
                height: 50px;
                margin: 0px;
                padding: 0px;
                line-height: 50px;
            }

                .pop-table tr td {
                    /*border: solid 1px black;*/
                }

        .button-area {
            width: 100%;
            height: 50px;
            float: left;
        }

        .button-left {
            width: 50%;
            float: left;
            padding: 5px;
            box-sizing: border-box;
        }

        .button-right {
            width: 50%;
            float: right;
            padding: 5px;
            box-sizing: border-box;
        }

        .text-input {
            width: 230px;
            height: 30px;
            line-height: 20px;
            padding: 5px;
        }

        .text-select {
            width: 244px;
            height: 43px;
            line-height: 33px;
            padding: 5px;
        }

        .role-edit {
            width: 100%;
            height: auto;
            /*border: solid 1px #CCC;*/
            box-sizing: border-box;
        }

            .role-edit ul {
                margin: 10px 0px 10px 0px;
                padding: 0px;
                border: 0px;
                list-style: none;
            }

                .role-edit ul li {
                    width: 166px;
                    height: 30px;
                    text-align: left;
                    /*line-height: 30px;*/
                    padding-left: 10px;
                    box-sizing: border-box;
                    float: left;
                }
    </style>
</body>
</html>


<script type="text/javascript">

    //删除一条记录
    function DeleteRecord(id) {
  
		
        ShowBox({ Content: "确定要删除这条记录吗？" }, function () {
             $.ajax({
                url: "<%=path%>/organization/turnDelOrganization.htm",
                data: {"or_id":id},
                type : "POST",
                dataType: "json",
                success: function (result) {
                    var resultData = $.parseJSON(result);
                    if(resultData.status=="100000"){
                      ShowBox({ Content: "车辆信息删除成功!" });
                      setTimeout(function () {
                        window.location.reload();
                      }, 700);
                    } 
                }
            });
          
        });
    }
</script>

</body>
</html>